<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	    		xmlns:ui="http://java.sun.com/jsf/facelets"
	  			xmlns:h="http://java.sun.com/jsf/html"
	  			xmlns:f="http://java.sun.com/jsf/core"
                xmlns:sf="http://www.springframework.org/tags/faces"
                xmlns:cs="http://myfaces.apress.com/custom"
				template="/WEB-INF/layouts/standard.xhtml"
				xmlns:a4j="http://richfaces.org/a4j"
				xmlns:rich="http://richfaces.org/rich">

	<ui:define name="content">
	
		<div class="section">
			<h2>${model}s</h2>
			<h:form id="Room">
				<h:messages errorClass="errors" />				
				<fieldset>
					<div class="field">
						<div class="label">Room Number:</div>
						<div class="input">
							<sf:clientTextValidator required="true">
								<h:inputText required="true" requiredMessage="Room Number is required !" id="name" value="#{room.roomNumber}">
									<rich:beanValidator/>
								</h:inputText>
							</sf:clientTextValidator>						
						</div>
					</div>
					<div class="field">
						<div class="label">Building</div>
						<div class="input">
							<rich:comboBox 	required="true" 
											requiredMessage="Building is required !" 
											id="roomBuilding" 
											value="#{room.building}"
											suggestionValues="#{buildingController.all}"
											converter="#{buildingConverter}">								
							</rich:comboBox>
						</div>
					</div>
					<div class="field">
						<div class="label">Floor:</div>
						<div class="input">
							<sf:clientTextValidator required="true">
								<h:inputText required="true" requiredMessage="Floor is required !" id="floor" value="#{room.floor}">
									<rich:beanValidator/>
								</h:inputText>
							</sf:clientTextValidator>
						</div>
					</div>
					<div class="field">
						<div class="label">Number of Beds:</div>
						<div class="input">
							<sf:clientTextValidator required="true">
								<h:inputText required="true" requiredMessage="Number of Beds is required !" id="number-of-beds" value="#{room.numberOfBeds}">
									<rich:beanValidator/>
								</h:inputText>
							</sf:clientTextValidator>
						</div>
					</div>
					<div class="field">
						<div class="label">Is Dormitory ? :</div>
						<div class="input">
							<h:selectBooleanCheckbox id="isDormitory" value="#{room.dormitory}"/>
						</div>
					</div>
					<div class="field">
						<div class="label">Has AC? :</div>
						<div class="input">
							<h:selectBooleanCheckbox id="hasDormitory" value="#{room.ac}"/>
						</div>
					</div>
					<div class="buttonGroup">
						<sf:validateAllOnClick>
							<h:commandButton disabled="#{editing}" id="submit" action="add" value="Add"/>&#160;
							<h:commandButton disabled="#{!editing}" action="update" value="Update"/>&#160;
						</sf:validateAllOnClick>
						<h:commandButton id="cancel" immediate="true" value="Cancel" action="cancel"/>
					</div>		
				</fieldset>	
						
				<rich:dataTable value="${rooms}" var="aBean">
					<rich:column>
							<f:facet name="header">
								<h:outputText value="Edit" />
							</f:facet>
							<h:commandButton disabled="#{editing}" immediate="true" value="Select" action="select"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">
								<h:outputText value="Delete" />
							</f:facet>
							<h:commandButton disabled="#{editing}" immediate="true" value="Delete"  action="delete"
							onclick="if(!showConfirmation('Are you sure to remove : Room #{aBean.roomNumber} from  Building #{aBean.building.name} ?')) return false;"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">Building</f:facet>
							<h:outputText value="#{aBean.building.name}"/>
						</rich:column>			
						<rich:column>
							<f:facet name="header">Room Number</f:facet>
							<h:outputText value="#{aBean.roomNumber}"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">Floors</f:facet>
							<h:outputText value="#{aBean.floor}"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">Dormitory</f:facet>
							<h:outputText value="#{aBean.dormitory}"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">AC</f:facet>
							<h:outputText value="#{aBean.ac}"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">Beds</f:facet>
							<h:outputText value="#{aBean.numberOfBeds}"/>
						</rich:column>
				</rich:dataTable>
			</h:form>
		</div>
	</ui:define>
</ui:composition>